library Wave14b initializer init requires LegacySystem, DeltaUtils, LostCauseMAIN, ContainmentMAIN, MagnificentBastardsMAIN

    private function RemoveUnitAIHelo takes nothing returns nothing
        if GetPlayerController(GetOwningPlayer(GetFilterUnit()))!=MAP_CONTROL_USER then
            call RemoveUnit(GetEnumUnit())
        endif
    endfunction
    
    private function SlowPatrol takes nothing returns nothing
        call ShiftMoveSpeed(GetEnumUnit(),-100.0)
    endfunction

    private function EndSlowPatrol takes nothing returns nothing
        call ShiftMoveSpeed(GetEnumUnit(),100.0)
    endfunction

    private function Chapter2Climax takes nothing returns nothing
        call FogTransition(0.03)
        call GankMarine(Player(13),'n004',2+udg_Spawn,1600,2000)
        call PolledWait(5.)
        call FogTransition(0.05)
        call RandomSpawn('u00L',4,IMinBJ(5, udg_Players)) //Blink
        call GankMarine(Player(14),'n002',udg_Spawn,1600,2000)
        call GankMarine(Player(13),'n004',udg_Spawn,1600,2000)
        if udg_Players>=6 then
            call RandomSpawn('ugar',1,2)
            call RandomSpawn('n002',1,2)
        endif
        call PolledWait(5.)
        call RandomSpawn('ugar',1,GetRandomInt(1,udg_Spawn)) //Gargoyle
        call GankMarine(Player(13),'n004',2+udg_Spawn,1600,2000)
    endfunction
    
    private function Wave14c takes nothing returns nothing
        local integer i = 1
        local integer i2 = 1
        local integer cobra = 1
        local integer secure = 0
        local group g
        local real x
        local real y
        local real facing
        set udg_CurrentWave = 14
        set udg_Visibility = 70
        call IntermissionRestore()
        set udg_Visibility = 71
        call IntermissionRestore()
        call GenericActions.execute()
        set i = 1
        loop
            exitwhen i > 5
            call SpawnRectRandom(gg_rct_ADTSpawnWest,Player(14),'u00C',GetRandomInt(0,3)*udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnEast,Player(14),'u00C',GetRandomInt(0,4)*udg_Spawn)
            if GetRandomInt(0,1)==1 then
                call GankMarine(Player(14),'u005',udg_Spawn,1200,1800)
                call GankMarine(Player(14),'u005',udg_Spawn,1200,1800)
            endif
            if i==1 then
                call RadioChat(udg_DeltaLeader, 5.0, "|cfff3ad00SSgt. Thompson|r : Gargoyles!" )
                set i2 = 1
                loop
                    exitwhen i2>8
                    call RemoveUnit(udg_Pilot[i2])
                    set i2=i2+1
                endloop
                if GetWidgetLife(udg_AirfieldF22[1])>0.405 then
                    call PauseUnit(udg_AirfieldF22[1],false)
                    call SetUnitTimeScalePercent(udg_AirfieldF22[1],100.0)
                    call IssuePointOrder(udg_AirfieldF22[1],"move",12961.0,8392.0)
                    call AttachSoundToUnit(gg_snd_F22Engine, udg_AirfieldF22[1])
                    call SetSoundVolume(gg_snd_F22Engine,127)
                    call StartSound(gg_snd_F22Engine)
                endif
                loop
                    exitwhen cobra>3
                    if GetWidgetLife(udg_AH1Cobra[cobra])>0.405 then
                        call SetUnitTimeScalePercent(udg_AH1Cobra[cobra],50.0)
                    endif
                    set cobra=cobra+1
                endloop
                set cobra=1
                call GeneralText(5.0, "|cfff3ad00CWO Wolcott|r : We're pulling in power for takeoff. Cover us." )
            endif
            call SpawnRectRandom(gg_rct_ADTSpawnSouth,Player(14),'u00C',GetRandomInt(0,3)*udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnNorth,Player(14),'u00C',GetRandomInt(1,3)*udg_Spawn)
            if i==2 and GetWidgetLife(udg_AirfieldF22[1])>0.405 then
                call IssuePointOrder(udg_AirfieldF22[1],"move",12961.0,8500.0)
            elseif i==3 and GetWidgetLife(udg_AirfieldF22[2])>0.405 then
                call IssuePointOrder(udg_AirfieldF22[2],"move",12961.0,8500.0)
            endif
            call PolledWait(4.)
            if i==2 then
                if GetWidgetLife(udg_AirfieldF22[1])>0.405 then
                    call IssuePointOrder(udg_AirfieldF22[1],"move",12961.0,15000.0)
                    set udg_soundpath = "Sound\\Interface\\GlueScreenMeteorLaunch3.wav"
                    call PlaySoundPath.execute()
                    call SetUnitFlyHeight(udg_AirfieldF22[1],600.0,100.0)
                    //call SmoothUnitResize(udg_AirfieldF22[1],5.0,3.30,4.2)
                    call ShiftMoveSpeed(udg_AirfieldF22[1],410.0)
                endif
                if GetWidgetLife(udg_AirfieldF22[2])>0.405 then
                    call PauseUnit(udg_AirfieldF22[2],false)
                    call SetUnitTimeScalePercent(udg_AirfieldF22[2],100.0)
                    call IssuePointOrder(udg_AirfieldF22[2],"move",12961.0,8392.0)
                    call AttachSoundToUnit(gg_snd_F22Engine, udg_AirfieldF22[2])
                    call SetSoundVolume(gg_snd_F22Engine,127)
                    call StartSound(gg_snd_F22Engine)
                endif
                loop
                    exitwhen cobra>3
                    if GetWidgetLife(udg_AH1Cobra[cobra])>0.405 then
                        set secure=secure+1
                        call SetUnitTimeScalePercent(udg_AH1Cobra[cobra],100.0)
                        set facing = GetUnitFacing(udg_AH1Cobra[cobra])
                        set x = GetUnitX(udg_AH1Cobra[cobra])
                        set y = GetUnitY(udg_AH1Cobra[cobra])
                        call RemoveUnit(udg_AH1Cobra[cobra])
                        set udg_AH1Cobra[cobra] = CreateUnit(Player(11),'hgyr',x,y,facing)
                        call SetUnitFlyHeight(udg_AH1Cobra[cobra],5.00,99999.0)
                        //call SmoothUnitResize(udg_AH1Cobra[cobra],0.38,1.0,0.1)
                        call TriggerSleepAction(0.)
                        call SetUnitFlyHeight(udg_AH1Cobra[cobra],500.0,175.0)
                        //call SmoothUnitResize(udg_AH1Cobra[cobra],1.1,1.1,2.8)
                    endif
                    set cobra=cobra+1
                endloop
                call PolledWait(3.)
                set g = GetUnitsOfTypeIdAll('hgyr')
                call ForGroup(g,function SlowPatrol)
                call GroupPointOrder(g,"patrol",11700.0,9300.0)
                call DestroyGroup(g)
                if GetWidgetLife(udg_AirfieldF22[1])>0.405 then
                    set secure=secure+1
                    call RemoveUnit(udg_AirfieldF22[1])
                endif
            elseif i==3 then
                if GetWidgetLife(udg_AirfieldF22[2])>0.405 then
                    call IssuePointOrder(udg_AirfieldF22[2],"move",12961.0,15000.0)
                    set udg_soundpath = "Sound\\Interface\\GlueScreenMeteorLaunch3.wav"
                    call PlaySoundPath.execute()
                    call SetUnitFlyHeight(udg_AirfieldF22[2],600.0,100.0)
                    //call SmoothUnitResize(udg_AirfieldF22[2],5.0,3.30,4.2)
                    call ShiftMoveSpeed(udg_AirfieldF22[2],410.0)
                    call PolledWait(5.)
                    if GetWidgetLife(udg_AirfieldF22[2])>0.405 then
                        set secure=secure+1
                        call RemoveUnit(udg_AirfieldF22[2])
                    endif
                endif
                call RadioChat(udg_DeltaLeader, 10.0, "|cfff3ad00SSgt. Thompson|r : It's good to see air support. Stay behind the turrets." )
            endif
            call PolledWait(4.)
            call SpawnRectRandom(gg_rct_ADTSpawnWest,Player(14),'u00C',GetRandomInt(1,2)*udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnEast,Player(13),'u00C',GetRandomInt(1,2)*udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnSouth,Player(14),'u00C',GetRandomInt(1,2)*udg_Spawn)
            call SpawnRectRandom(gg_rct_ADTSpawnNorth,Player(13),'u00C',GetRandomInt(1,2)*udg_Spawn)
            set i=i+1
        endloop
        call PolledWait(10.)
        set g = GetUnitsOfTypeIdAll('hgyr')
        call GroupPointOrder(g,"move",14000.0,7000.0)
        call ForGroup(g,function EndSlowPatrol)
        call FogTransition(0.02)
        call PolledWait(5.)
        call RadioChat(udg_DeltaLeader, 10.0, "|cfff3ad00SSgt. Thompson|r : Sector C needs attention. I trust you boys will be fine. Have a good 'un." )
        call SetImmortalSpawnEnabled(false)
        call SetCrepitusSpawnEnabled(false)
        call SetGhoulSpawnEnabled(false)
        call Chapter2Climax.execute()
        call PolledWait(10.)
        call DeltaExit.execute()
        call ADTCleanup()
        set i = 1
        if udg_Players>1 and GetWidgetLife(udg_AITarget)>0.405 and secure>2 and udg_Mode==1 then
            call ALICE2Text(10.0, "Jefferson Airbase Successfully Defended. |cff1e90ff75 XP|r awarded to all Marines." )
            loop
                exitwhen i>udg_InitialPlayers
                if GetPlayerSlotState(ConvertedPlayer(udg_Sorted[i]))!=PLAYER_SLOT_STATE_LEFT then
                    set udg_Experience[udg_Sorted[i]] = udg_Experience[udg_Sorted[i]] + 75
                endif
                set i=i+1
            endloop
        endif
        call PolledWait(25.)
        call ForGroup(g,function RemoveUnitAIHelo)
        call DestroyGroup(g)
        set g = null
        set udg_IntenseSpawn = 0
        
        if udg_SquadXP>45000 and GetRandomInt(0,2)==1 and (udg_Players>2 or udg_SquadXP>100000) then
            call LostCauseMAIN()
        elseif GetRandomInt(0,2)!=1 then
            call MagnificentBastardsMAIN()
        else
            call ContainmentMAIN()
        endif
    endfunction

    private function Wave14b takes nothing returns nothing
        local integer i = GetRandomInt(1, udg_Players)
        local integer i2 = GetRandomInt(1, udg_Players)
        set udg_CurrentWave = 14
        set udg_Visibility = 70
        call IntermissionRestore()
        set udg_Visibility = 71
        call IntermissionRestore()
        call GenericActions.execute()
        call M242Drop.execute()
        call PolledWait(10.00*udg_Pace)
        call RadioChat(udg_DeltaLeader, 10.0, "|cfff3ad00SSgt. Thompson|r : That's it, haul ass to the manual drop site." )
        call RandomSpawn('z002',1,udg_Players) //Slasher
        call PolledWait(60.0*udg_Pace)
        if udg_Players>1 then
            call FieldChat(udg_Hero[udg_Sorted[i]], 8, udg_Pcolors[udg_Sorted[i]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i])) + "|r : This is bullshit, man. We got to get the hell outta here." )
            call PolledWait(4.0)
            loop
                exitwhen i2!=i
                set i2 = GetRandomInt(1, udg_Players)
            endloop
            call FieldChat(udg_Hero[udg_Sorted[i2]], 8, udg_Pcolors[udg_Sorted[i2]] + GetPlayerName(ConvertedPlayer(udg_Sorted[i2])) + "|r : I'm with you, but there's nowhere we can go." )
        endif
        call PolledWait(60.0*udg_Pace)
        call FogTransition(0.02)
        call RadioChat(udg_DeltaLeader, 10.0, "|cfff3ad00SSgt. Thompson|r : Sector C needs attention. I trust you boys will be fine. Have a good 'un." )
        call SetDeltaSpawnEnabled(false)
        call PolledWait(10.0)
        call SetImmortalSpawnEnabled(false)
        call SetCrepitusSpawnEnabled(false)
        call SetGhoulSpawnEnabled(false)
        call DeltaExit.execute()
        call Chapter2Climax.execute()
        call PolledWait(35.)
        set udg_IntenseSpawn = 0

        if udg_SquadXP>40000 and GetRandomInt(0,2)==1 and (udg_Players>2 or udg_SquadXP>100000) then
            call LostCauseMAIN()
        elseif GetRandomInt(0,2)!=1 then
            call MagnificentBastardsMAIN()
        else
            call ContainmentMAIN()
        endif
    endfunction


    private function init takes nothing returns nothing
        call RegisterFunction("Wave14b", function Wave14b)
        call RegisterFunction("Wave14c", function Wave14c)
        //call ExecuteRegisteredFunction("Wave12b")
    endfunction
endlibrary